import pdb

# convert html unicode string to hex representation. 
# html unicode string use % as escape symbol, eg. 'Fe%c3%adst'
def HtmlStrToHex(str):
    result = ''
    i = 0
    while i<len(str):
        if not str[i] == '%':
            result = result + str[i].encode('hex')
            i = i + 1
        else:
            result = result + str[i+1:i+3]
            i = i+3
            
    return result
    
def is_equal(html_str, unicode_str):
    if unicode_str.encode('utf8').encode('hex') == HtmlStrToHex(html_str):
        return True
    else:
        return False

def ConcatString(str1,  str2):    
    return str1 + ', ' + str2

    

def ReplaceText(text, replace_pairs):
    allText = text
    for old, new in replace_pairs.iteritems():
        allText       = allText.replace(old,new.encode('utf8'))
        
    return allText
    

if __name__ == '__main__':
    print HtmlStrToHex('Fe%c3%adst')
    
    print is_equal('Fe%c3%adst',  u'Fe\xedst')
